package com.leyou.controller;

import com.item.dto.SpecGroupDTO;
import com.item.dto.SpecParamDTO;
import com.leyou.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//http://api.leyou.com/api/item/spec/groups/of/category/?id=204
@RestController
@RequestMapping("spec")
public class SpecController {

    @Autowired
    private SpecService specService;

    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> queryGroupByCategory(
        @RequestParam("id") Long id
    ){
        return ResponseEntity.ok(specService.queryGroupByCategory(id));
    }

//    api/item/spec/params?gid=1/**
//     * 查询规格参数
//     * @param gid 组id
//     * @param cid 分类id
//     * @param searching 是否用于搜索
//     * @return 规格组集合
//     */
    @GetMapping("params")
    public ResponseEntity<List<SpecParamDTO>> querySpecParams(
            @RequestParam(value = "gid",required = false) Long gid,
            @RequestParam(value = "cid",required = false) Long cid,
            @RequestParam(value = "searching",required = false) Boolean searching
    )
    {
        return ResponseEntity.ok(specService.querySpecParams(gid,cid,searching));
    }

    /**
     * 查询规格参数组，及组内参数
     * @param id 商品分类id
     * @return 规格组及组内参数
     */
    @GetMapping("/of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecsByCid(@RequestParam("id") Long id){
        return ResponseEntity.ok(specService.querySpecsByCid(id));
    }


}
